That is the real code, but I changed the names of the variables to protect the innocent and make it easier to understand/read in general.
But its incomplete, there are missing parts, there is nothing obvious to point to as the cause of the problem, see How do I post a question effectively?
You say shebang, initialization ... "do" etc. well that could be someting, but it could be nothing
Could be browser reloading HTTP request because you're not Post/Redirect/Get or any other kind of braino results