Yes, that was why paste
was good, because it avoids that.
You can also remove the trailing “, ” with:
perl -pe 's/, $//'
so
perl -pe 's/\n/, /' | perl -pe 's/, $//'
But yes, a surprisingly complicated problem to get right. And a good reminder that you really have to know what the limitations on the input and what the desired output is.