To pinpoint where your code fails: at the time you recurse, the $out->[$i] is undefined. This "undefined" is assigned to lexical $out in callee, and further assignment e.g. $out->[$i] = $in->[$i] autovivifies $out as array reference, but unfortunately it has no connection whatsoever with $out in caller. To fix, replace
$self->_recurse($in->[$i], $out->[$i]);
with
$self->_recurse($in->[$i], $out->[$i] //= []);
Plus, if (!$out->[$i]) should be written if (!defined $out->[$i]), or you'll never increment zero values.