:local listName "rdp_blacklist";
:local fileName "test.txt";
:local script2write "
:local counter;
:foreach counter in= [/ip firewall address-list find list=$listName] do={
:local ip [/ip firewall address-list get \$counter address];
:put \$ip;
};
";
:put $script2write;
:execute script=$script2write file=$fileName;