Just as an FYI, I had the same issue as VFT when I was learning CGI. The print $query->redirect('http://somewhere') ; must not appear AFTER a print $query->header() ; as it IS your header.
"Nothing is sure but death and taxes" I say combine the two and its death to all taxes!