Although Mnemonic explained this pretty well, I'll try to go into bigger detail what's going on:
you have here an object "actor" which occupies some memory space. As Mnemonic explained - you load the script
and everything outside the "event handlers" (those are the on "something" {} ) gets executed only once when your script gets
loaded. So this script gets executed once per scene entry. This way your leaving and returning to the scene fixed the problem
because the script got executed again which in turn again set the Tom variable to your new actor which was now valid again.
When you call Game.UnloadObject, your actor object in memory gets destroyed and together with it all references (so your variable
Tom no longer works). So your idea that you can't change the local variable from outside the script is correct, but you forgot, that
this variable points to a global object which got destroyed, so your local variable points to void place, because the space allocated for
the new object was not the same.
This is an example of the most terrible-to-find bugs ever, because if it was for example C++, you could meet a condition when the memory could be allocated in the same place so it would sometime work and sometime won't. This kind of bugs make coders to pull their hair out.