infile = Path(r"C:\Temp\slovar.txt")
words = infile.read_text(encoding="utf-8").splitlines()
print(words)
#['каждый', 'охотник', 'желает', 'знать', 'где', 'сидит', 'фазан']
morph = MorphAnalyzer()
items = [(str(morph.parse(w)[0].tag.POS), w) for w in words]
print(items)
#[('ADJF', 'каждый'), ('NOUN', 'охотник'), ('VERB', 'желает'), ('INFN', 'знать'), ('ADVB', 'где'), ('VERB', 'сидит'), ('NOUN', 'фазан')]
for g, it in groupby(sorted(items), key=lambda x: x[0]):
otufile = infile.parent / f"{g}.txt"
otufile.write_text("\n".join([word for pos, word in it]),
encoding="utf-8")