Some code for writing to file