in reply to file creating AND writing error

Also, the while loop is trying to read from the empty file you've just created.

Dave.