Why does my function create extra empty files?

The problematic line is the one for the transition_post_status action’s callback as the input parameter is post status (string) but not post ID (integer):

https://developer.wordpress.org/reference/hooks/transition_post_status/