I'm writing a lot of test nowadays (finally!) and currently I have a lot of
duplicated code in them. This is because I'm testing a simple backup solution
and many tests of mines requires backup scenarios to be present in a temporary
folder.
I'd just add that this seems like a perfect situation to upgrade to some
xUnit-like test framework, e.g.: Test::Class to prevent code
duplication.
As a bonus you get also Test(startup) and Test(shutdown) subs to wrap your
tests in some particular "environment" without leaving garbage around once
finished.