mod_perl is "persistent" meaning processes hang around for a while, and unless properly managed variables are not going to be reassigned like you think they are; it's not unlike a "stale cache" problem.
I believe that what you are seeing is due to this persistence, so you need a handler that will recompile the script each time a requests is handled by Apache. This PerlResponseHandler is ModPerl::PerlRun.
See Re: mod-perl configuration under Apache2.
Last note, mod_perl is really nice once you understand that it a way to hook deeply into Apache's requesting life cycle to facilitate an application, but it'd be easier for you to port it to a pure CGI environment that doesn't try to be smart with persistence. CGI is much more akin to running it at the command line - just be careful of %ENV not being what you expect it to be.