added 'write_to_filename' method to Grid class