in reply to Archive::Tar

This isn't really related to your problem (which I see you've solved now), but if you're going to be extracting *all* of the files in the archive (which you are, in the example above), you can just use the extract_archive class method:
Archive::Tar->extract_archive("$dirname/$file");
The extracted files will be placed under the current working directory. Archive::Tar will automatically detect when it's dealing with a compressed archive.