<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_to_file(chats, chatfile):
 """called every time chats are modified"""

    with open(chatfile, 'w') as handler:
        handler.write('\n'.join((str(id_) for id_ in chats)))