This is an easy and not enough tested script, you may also enable it to start at boot.

Read about systemctl:

So create a file in /lib/systemd/system

touch python_service.service

sudo nano python_service.service

run the script with (when it is done and has no erros):

This is my test script:

It prints service and writes to a file:

sudo systemctl start python_service.service

sudo systemctl status python_service.service

sudo systemctl stop python_service.service

Now lets clean the file and run it as a service:

sudo systemctl start python_service.service

Now lets stop it and check status, and check the file

And the file is full, nice, but the dir is now / (have to check that)

Change python exe to env exe (have to test this):