FTP send "ghost" - deleted file

Hi,

I got some strage problem. Few day spent and cant make it work.
I make script to scan WLAN and upload results to FTP.
Script work, but fetch to FTP sends always same, first file wich is deleted (first file of day, or reboot) instead of newly created.
Two days trying to fix this but no luck.

I try on 7.16 and 7.6 - same problem.

board-name: hAP lite
model: RB941-2nD
revision: r3
current-firmware: 7.6

/log info "Start Scan"
/interface/wireless/enable 0
delay 15s
interface/wireless/set 0 mode=ap-bridge 
delay 5s
/interface/wireless/scan wlan1 background=yes duration=30s save-file=wlan1scan.txt
delay 5s
/interface/wireless/disable 0
delay 5s
:local filename "wlan1scan.txt"
:local ident [/system/identity/get name]
:local filecontent [/file get $filename contents]
:local newfilecontent "$ident\r\n$filecontent"
:local newfile "$ident.txt"
:if ([:len [/file find where name=$newfile]] = 0) do={/file/print file=$newfile; :delay 1s; /file/set $newfile contents=""} else={/file/set $newfile contents=""}
/file/set $newfile contents=$newfilecontent
:delay 5s
/tool fetch address=x.x.x.x mode=ftp user=someuser password=somepassword src-path=$newfile dst-path=$newfile upload=yes port=21
/file remove $newfile
/log info "End Scan"

How do you run the script? Ftom scheduller? If yes, how exactly does the scheduller job definition look like?

Since the script uses local variables, I guess that having scheduler run script at midnight (or whatever the start time is) and repeat it every N minutes for 24 hours (and do it every day)… is not the same as having scheduler multiple entries (e.g. each time-shifted by N minutes relative to previous one), each running script once and repeat every day.

Script is in test phase, I run it manually.