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)))
called every time chats are modified