The error message just tells You that the directory $somepath/output exists. Your variables $temp1, $temp2 seem to have been empty (see the trailing slashes in the error message).
Besides the push statement in line 27 declares a second array @folder_names.
You should really uncomment the "use strict" like already said. This will help You find and correct errors like this one.