<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_file(self, filename, binary=False, **kwargs):
 """ Save gridded data to a file. Usage ----- x.to_file(filename, [binary, **kwargs]) Parameters filename : str Name of output file. For text files (default), the file will be saved automatically in gzip compressed format if the filename ends in .gz. binary : bool, optional, default = False If False, save as text using numpy.savetxt(). If True, save as a 'npy' binary file using numpy.save(). **kwargs : keyword arguments, optional Keyword arguments of numpy.savetxt() and numpy.save(). """

        if binary is False:
            _np.savetxt(filename, self.data, **kwargs)
        elif binary is True:
            _np.save(filename, self.data, **kwargs)
        else:
            raise ValueError('binary must be True or False. '
                             'Input value is {:s}'.format(binary))