Greetings Fellow Monk!
I see in your script that you are trying to generate for your users random passwords.
I would like to recommend to you this module:
Crypt::GeneratePassword.
I have found it to be quite useful. Here is a snippet of code to demo it:
#!/usr/bin/perl -w
use strict;
my $minlen=6;
my $maxlen=10;
use Crypt::GeneratePassword qw(word chars);
my $word = chars($minlen,$maxlen);
print "$word\n";