Wow. You are really reinveting the wheel here. The
EMBOSS tools can do this as well. Here's a bioperl solution of one new file per sequence in the original file, named by accession number. No one should really waste their time writing a genbank parser unless it is homework... Note that 'genbank' can be substituted below with any of the supported formats (fasta, embl,swissprot,etc).
use Bio::SeqIO.
my $in = Bio::SeqIO->new(-format => 'genbank', -file => $genfile);
while(my $seq = $in->next_seq ){
my $acc =$seq->accession_number;
my $out = Bio::SeqIO->new(-format => 'genbank',-file=>">$acc.gb");
$out->write_seq($seq);
}