<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_collection(self, filename, collection):
 """ Writes a collection of stop words into a file. """

        collection = sorted(list(collection))
        with open(filename, 'wb+') as fd:
            fd.truncate()
            fd.write('\n'.join(collection).encode('utf-8'))