You should probably print out the path on the line before you try to create the file. Make sure nothing screwy is going on, like the $FILE_NUMBER variable resetting and having you try to open the same file simultaneously on two separate threads (or whatever).