write model to file