<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write( self, filepath, fully_qualified=True, pretty_print=False, encoding="UTF-8" ):
 """Serialize and write this METS document to `filepath`. The default encoding is ``UTF-8``. This method will return a unicode string when ``encoding`` is set to ``unicode``. :param str filepath: Path to write the METS document to """

        root = self.serialize(fully_qualified=fully_qualified)
        tree = root.getroottree()
        kwargs = {"pretty_print": pretty_print, "encoding": encoding}
        if encoding != "unicode":
            kwargs["xml_declaration"] = True
        tree.write(filepath, **kwargs)