Perl to the rescue:
#!/usr/bin/perl
use warnings;
use strict;
my @lines = <>;
chomp @lines;
my %count;
$count{$_}++ for @lines;
my $OUT;
my $x;
for my $separator (grep $count{$_} > 1, keys %count) {
for my $line (@lines) {
open $OUT, '>', 'A' . ++$x . '.txt' or die $!
if not $OUT or $separator eq $line;
print {$OUT} "$line\n";
}
undef $OUT;
}