Don't open and close the file over and over again. Take advantage of the fact that your file is sorted.
my $fh;
my $last;
while (<>) {
my ($file) = /^([^,]+),/;
if (!defined($last) || $file ne $last) {
open($fh, '>', "$file.txt")
or die($!);
}
print $fh $_;
$last = $file;
}