@bluecrow76 May I know what is your RouterOS version, It seems " execute script=$a file=$filename" only works in early version such as 6.45.9, it doesn't work on 6.47.3.
I don't recall the exact version I was running when I posted this back in April, but I would have been running whatever was stable at the time.
To test, I just ran the code exactly as listed in my previous post on a 6.47.4 CHR and it worked as expected. My only advise would be to make sure that you're filenames don't have any spaces in them if you're not explicitly putting the variables inside of quotes. Below is a "/system scripts export" of the script as I ran it on the CHR.
# sep/24/2020 01:07:15 by RouterOS 6.47.4
# software id =
#
#
#
/system script
add dont-require-permissions=no name=netwatches-to-csv policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="#\
\_MSHARP 20200412\r\
\n# Print netwatch statuses in CSV format. Allows quick import into Excel\
\r\
\n{\r\
\n# print header\r\
\n:local message \"\\\"host\\\",\\\"status\\\",\\\"since\\\",\\\"disabled\
\\\",\\\"comment\\\"\"\r\
\n:put \$message\r\
\n# print each netwatch\r\
\n:foreach n in=[/tool netwatch find] do={\r\
\n\t:local comment [/tool netwatch get \$n comment]\r\
\n\t:local host [/tool netwatch get \$n host]\r\
\n\t:local status [/tool netwatch get \$n status]\r\
\n\t:local since [/tool netwatch get \$n since]\r\
\n\t:local disabled [/tool netwatch get \$n disabled]\r\
\n\t:local message \"\\\"\$host\\\",\\\"\$status\\\",\\\"\$since\\\",\\\"\
\$disabled\\\",\\\"\$comment\\\"\"\r\
\n\t:put \$message\r\
\n}\r\
\n}"
add dont-require-permissions=no name=\
netwatches-to-csv_save-output-to-txt-file policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="#\
\_MSHARP 20200412\r\
\n# Save the output of the netwatches-to-csv script to a txt file\r\
\n# Solution found in the link below:\r\
\n# https://forum.mikrotik.com/viewtopic.php\?t=130448#p645867\r\
\n{\r\
\n:local a [/system script get netwatches-to-csv source]\r\
\n:local outFile \"netwatches-to-csv.csv\"\r\
\nexecute script=\$a file=\$outFile\r\
\n}"