as per docs...you never unlock a file..just close it and it becomes unlocked and is flushed. unlocking before close (where it's flushed) is causing the problem....especially that you don't write "\n", which forces a buffer flush also.
Comment on Re: Re: can't write a variable to a file