I cannot write the contents of a variable to a file. The contents of the mikrotik directory are written instead of the v

I cannot write the contents of a variable to a file. The contents of the mikrotik directory are written instead of the variable.

I cannot write $obsah to a the file
the penultimate line is still correct
:log info - show me the correct content but the last command writes a directory list to the file. Not content of variable $obsah.

:local obsah;
:local filename "test.txt";
/ip dhcp-server lease
:foreach i in=[find] do={
:set obsah ($obsah . "\n" .  [get $i host-name] . "," . [get $i address]);
}
/file print file=$filename;

# here is the right content that I need to write to a file
:log info $obsah;

# But the list of the mikrotik file directory is written to the file instead of variable     !???????
/file set $filename contents=$obsah;