Implementing saveToFile() method.