A script that changes layouts could trip any number of script triggers including OnLayoutEnter.
I use the following method to keep a script from tripping triggers:
Set Variable [ $$TriggersOff ; True ]
#Put the rest of the script here
Set Variable [$$TriggersOff ; False ]
If you have points in your script where a Halt or Exit terminates the script, you'll need to add that second set variable step just before the Halt or Exit script.
Then, in every trigger controlled script that might be tripped by such a script, I put the entire script inside an IF block like this:
If [ Not $$TriggersOff ]
#Rest of script goes here
This will keep your trigger controlled scripts from being performed when a script trips their triggers.