Implementation of saveToFile option