in reply to Access is denied

Maybe you want to use "lsof" on linux to find out what is blocking your file.
On Windows you maybe want to use a sysinternals (now Microsoft) tool to see which files are open by which process,
I leave it to you to find the appropriate tool ...
It couldnt be that your scripts locks the open files cause there is an error?
Your node was hard to read. Perhaps you could give a "formatted" sample code where people could see how you accomplish the opening e.g.