To resolve this issue, you must pause the execution of the script, so that the commands are saved locally before they are executed after the reboot.
To pause the execution of the script, use sleep 30 (30 seconds) after the %firstboot command and before the reboot command. This gives sufficient time for the commands to be saved locally.