Yep, your not locking the file to force other parts of the code attemtping to log to wait.
You check the file exists, if not create it and if it does you open it, what if anotehr program has opened the file for editing. You get your access denied problem, I can't guarantee this is the issue from your code all I can say is you have not shown code where you do lock the file or where you check if the file is locked.
So it's possible the file is not always released properly or another program, or even the same one is already writing to the file.