How to print a text file from a web page on a button click

I’m building an html/css/js application, no additional libraries.

The application collects some data from the user and, when he clicks the ‘COMPILE’ button, the data is processed in a certain way and displayed in a div.

I would like that when the user clicks the button the application creates a log file, i.e. a text file saved in a certain directory, containing in textual form the state of the application at the time of the click.

How can I create a text file from a web page?