The first step is improving your program so that it checks what went wrong. When you open and write into a file, check the return values in case the file could not be accessed. You can also read back what you've written, and compare.

When it is confirmed that the user can not write into the file, let him do some simple tests, f.i. writing with Notepad in a file in the same folder. If that also fails, it's an access right problem. Otherwise, it's some other bug in your script.