in reply to opening files where name is a concatenation of variable

Your code has some small inconsistencies:
    my $tempname = $basedir . '/output/file.txt';
You might use string interpolation here, like: "${basedir}/output/file.txt";
    open (OUTHANDLE, ">$tempname") or die;
Better use indirect filehandle and let it tell yourself *why* it died,
like: open my $oh1, '>', $tempname or die "$!";
    open (OUTHANDLE, ">$basedir . /output/file.txt") or die ;
This might be a typo, but you used string interpolation ("..") *AND*
tried "string concatenation" within the interpolated string. Which won't
do what you intended.

better use something like:
my $basedir = 'results'; my $tempname = "${basedir}/output/file.txt"; open my $oh1, '>', $tempname or die "$!"; open my $oh2, '>', "${basedir}/output/file.txt" or die "$!";
instead. The ${name} thingy would allow interpolation *within* words
like "${basedir}andmore", otherwise a variable $basedirandmore would
be searched but not be found.

Regards

mwa