add a function to write to temporary files (using regular FileIO lead to left over temporary files)