with open("test.txt", "a") as myfile:
myfile.write("appended text")
или
print("appended text", file=myfile)