added function to write to file