how to write data to a file