add writeToFile method