Thanks to @Wayne!
According to the issue Snakefile is run a second time if rule contains run directive #2350 I decided to use "shell" instead of "run" in my main_rule. This prevents snakemake from running the snakefile code twice. My working snakefile now looks like this:
#!/bin/python
print('import packages')
from datetime import datetime
import time
now = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
tarfile = now + '_stardist.tar'
print(tarfile)
rule all:
input: {tarfile}
rule main_rule:
input:
output: {tarfile}
shell:
"touch {tarfile}"