AFAIU, both File::Temp and File::Tempdir destroy the apporpriate files/directories when their object comes out of scope (e.g. at the end of {} block where it was declared using my).
Sorry if my advice was wrong.
Comment on Re^3: running string as perl script and pass into STDIN programatically