WriteToFile function

Writes data structure to a file