I don't have any error with your codes running
both in 6.31.4 and 6.40.2

What is your GS version?
Did the save.txt located in the same directory
of your program.