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