Fix file corruption when writing new file (cant skip past end of file)