Depending on your database server the statment
handles may still be open (or at least using resources
in the RDBMS)
even after you close your
database handle. Make sure you
have an $sth->finish() for each of your statment handles
(if you want to be really paranoid, undef them after you finish
them).
Try running your script (or a slimmed-down version of it) from
the command line and using the trace command ($dbh->trace(1)) and
examine the output.