Writing model to file