Flush to temporary file to prevent corruption