I would make the following suggestion:
var file = File.new()
var path = "user://example.txt"
# append lines to file
You can obviously shorten the code when you are sure that the file already exists.
The key method here is seek_end()