You increment _timer (local variable), but check timer (global variable). You also need to exit if _timer is too large, not when it is too small:
? _timer >= 300: exit
I suspect that after you first run the script, you do set the value of timer and that causes the script to exit early (that line will be ignored if timer is undefined).
One topic per thread please (where you have multiple questions about a specific subject, that can be O.K.)! Edit your original post to remove the jail question and start a new thread with it.
EDIT: Thanks for sorting that out.