Implemented save_to_file function