Batch printing script doesn't work after closing Dorico Pro 5.1

I made a batch print macro in Dorico on my M1 MacBook Pro, but it’s behaving quite bizarrely.

It only works as long as Dorico is still open after I recorded the macro, but it breaks after reopening Dorico and no longer attempts to print out any of my scores.

I’ve attached two different versions of a simple batch print macro I recorded for the forum. What am I doing wrong?
usermacro5.lua (9.1 KB)
usermacro6.lua (9.6 KB)