Added a rewind to write to reset the file pointer