Encode your character string first to utf-8:
str = "éé Ñ".encode("utf-8")
with open("file.txt", "wb") as f:
f.write(b"Hello, World!\r\n")
f.write(str)
with open("file.txt", "r", encoding="utf-8") as f:
for i, line in enumerate():
print(i, line)