I'm not clear if you specifically want to do this with just standard shell tools or not, but, Python is nearly universal on Linux these days. It can be done with a fairly simple program:
#!/usr/bin/python
import sys
data = { }
while True:
l = sys.stdin.readline()
if len(l)==0:
break
a,b = l.split()
data.setdefault(a, [ ]).append(b)
for k in sorted(data.keys()):
vs = data[k]
print k, ",".join(vs)
I ran it on 50,000,000 lines of data generated by the following C program, and it finishes in about 60 seconds of my years-old laptop:
#include <stdio.h>
#include <stdlib.h>
char letter() { return (rand() % (123-97)) + 97; }
void main(void)
{
int i;
for(i=0; i<50000000; i++)
printf("%c%c%c %c%c%c\n",
letter(), letter(), letter(),
letter(), letter(), letter());
}