with open(newfile, 'w') as outfile:
    with open(oldfile, 'r', encoding='utf-8') as infile:
        for line in infile:
            if line.startswith(txt):
                line = line[0:len(txt)] + ' - Truly a great person!\n'
outfile.write(line)
text = eval(input('Please enter the name of a great person: '))
letsgo = list(filter(text, 'Spanish', 'Spanish2'))
Как открыть файл с помощью оператора open with