fix write tmp file

need to test read/write