in reply to Local tests reveal no syntax error but...
Try placing your new code after:
my $words = $q->param('words'); [download]