Only opens a file once for writing