Did the script you tried include this by chance?
use String::Random;
Using pre-built modules when possible is generally a good rule in programming, but it can be tricky to work with in Lighthouse Studio as the code will only work if the current environment (local for Test Survey, Sawtooth servers for official hosting, or another environment if self-hosting) has the module installed. If you're comfortable with testing and potentially installing modules, that's great; otherwise, I usually stick with solutions that don't involve anything third-party modules.
For your situation, that solution would probably be just what you described.
[% Begin Unverified Perl
# Params
my @chars = ('a'..'z', 'A'..'Z', '0'..'9');
my $length = 8;
# Run
my $out;
for (my $i = 0; $i < $length; $i++) {
$out .= $chars[rand(@chars)];
}
return $out;
End Unverified %]