Using Raku (formerly known as Perl_6)
~$ raku -e 'my %h; for lines() { %h.push: .[1] => .[0] given .split(/ \s+ /) };
for %h.sort() {
spurt( ( .key ~ ".txt" ).IO, $_.value.join(",") ~ "\n", createonly => True);
};' file.txt
Above is a solution coded in Raku, a member of the Perl-family of programmming languages. An advantage of Raku is high-level support for Unicode.
Basically the problem as stated is a key/value problem, wherein all key/value pairs are stored in a %h hash. Every time you see a new second column (text) element you create a key, adding the corresponding first column (text) element as value. Since keys in a hash are maintained unique, subsequent values for the same key get pushed (or appended) to the same key.
Instead of taking input off the command line, you can write the code below which has the appropriate path hardcoded inside:
~$ raku -e 'my $in = "/path/to/file.txt".IO; my %h;
for $in.lines() { %h.push: .[1] => .[0] given .split(/ \s+ /) };
for %h.sort() {
my $out = IO::Spec::Unix.catpath($, $in.dirname, .key) ~ ".txt";
spurt( $out, $_.value.join(",") ~ "\n", createonly => True) };'
Other options include saving the code immediately above (inside the single quotes) as a script, and calling it at the command line with raku script.raku. Note above, the hardcoded script can be ported to other OSes, simply by changing the IO::Spec call as appropriate (to IO::Spec::Win32, IO::Spec::Cygwin, etc.).
https://docs.raku.org/language/hashmap#Mutable_hashes_and_immutable_maps
https://docs.raku.org/routine/split
https://raku.org