better file handling in replace_synonyms.py