That's great, thanks to all - using indirect File Handles would have presumably saved me from that so help from all three contributors. I'm very grateful...
using indirect File Handles would have presumably saved me from that
Indirect filehandles get automatically closed (and therefore flushed) when the variable holding them goes out of scope. So it may have solved your problem, but only if the filehandle variable went out of scope before you renamed the file. This technique doesn't automatically solve your problems.