Thank you johnmart for getting the whole thing posted.
I am not at all sure what is happening there, so hopefully we can get opinion on the matter.
It seems likely to me that what you have is some form of permission event.
The script appears to be killed by something not determined within the script.
I have never come across this before ...... but I do not use Xfce, so it may be something connected with the DE in use ......
GLib-GIO-Message: Using the 'memory' GSettings backend. Your settings will not be saved or shared with other applications.
Can you please run the script again, in the manner I described above ..... by opening a terminal and going to root, prior to launching the script?
I suggest opening a terminal at /home/john ..... then su to root ....... the put the full path of the script into the terminal to launch it.
I would like to compare the two outputs.
Thanks for your continued testing