<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def writefile(filename, data, binary=False):
 """ Write the provided data to the file. `filename` Filename to write. `data` Data buffer to write. `binary` Set to ``True`` to indicate a binary file. Returns boolean. """

    try:
        flags = 'w' if not binary else 'wb'
        with open(filename, flags) as _file:
            _file.write(data)
            _file.flush()
            return True

    except (OSError, IOError):
        return False