Use atexit so scripts terminated with ctrl-C can be profiled

Also adds --log-file option and hacks around an issue where passing
globals/locals to execfile breaks scripts that also parse arguments.
I'll probably add an option later once I understand the original
use case better.