serializeToFile function

Serialize a model to a file.