Writing to a .txt file with a form

Is there a simple way of writing some basic text to a .txt file using a form.
all i need in the form is to have a few different fields and that’s about it.
Also is there a way of posting it to the first line/before the first line of the document?

Basically all i want is to have a text file that ends up like this

Header1|content1|footer1
Header2|content2|footer2

and then using the form do this

New header|new content|new footer
Header1|content1|footer1
Header2|content2|footer2

can it be done?