In a pinch, log out using your shell's logout command, not by simply closing the session. The former exits cleanly, leaving you background processes running. The latter sends all of your backgrounded processes a HUP signal, which is probably killing your script.
But heed the advice of others and consider turning your script into a "real" daemon by disassociating it from the terminal to start with.