fixed a non threadsafe file write