perl -le'
push @{$h{$_->[0]}}, $_->[1] for map [split], <>;
print join " ", $_, @{$h{$_}} for sort keys %h;
' file
perl script.pl input_file.txt > output_file.txt
$\ = "\n";
push @{$h{$_->[0]}}, $_->[1] for map [split], <>;
print join " ", $_, @{$h{$_}} for sort keys %h;
more lengthy (and approximate) version,
$\ = "\n"; # append newline when invoking print
my %h;
# read lines from STDIN
while (<>) {
# split line on white spaces
my @F = split;
# push value of second column into $h{$F[0]} array
push @{ $h{$F[0]} }, $F[1];
}
# sort unique values of first column
for my $k (sort keys %h) {
# print value of first column,
# together with values belonging to it
print join " ", $k, @{ $h{$k} };
}