Well, you have many alternatives to create the file from a script (echo, printf, here documents and so on). The question is: where the input data comes from? Standard input? Another file?
Regarding the second part a simple awk code will do the sum for you:
Code:
awk '{_[$1] += $2} END{for (i in _ ) print i,_[i]}' file