How to make a script run when a file is opened
You can do this somewhat easily, by naming your text block *.py and checking the Register checkbox. 



Then the script contained in it will be run every time you open the .blend file.  This is great for registering handlers at the startup of a file.