Lines 34 and 35 of test2.pg are:
my $data = shift @$cell;
$opts = {%$cell};
The first of these lines expects $cell to be an array reference, and the second expects $cell to be a hash reference. I haven't dug into which kind of thing $cell is actually supposed to be, but there is some mistake here.
Does changing the latter line to
$opts = {@$cell};
fix things for you? For me it clears the error but I'm not paying attention to if the problem statement is what it should be and if answer checking is behaving as expected.
Once the perl error is removed though, there are PG warnings about how you are constructing the table. But there's a lot going on and I didn't dig deep to try to understand the table construction. Even the reduced test2.pg file is over 500 lines long. If you have a more minimal problem file I could look at, I might be able to suggest a more direct way to produce the PGML table.