My problem is not so much with the punctuation of either sentence but with the use of the word hopefully.
Hopefully is one of those words which has insinuated itself gradually--almost surreptitiously--into the English language. Instead of meaning "done in a hopeful manner," it now simply injects the idea of hope into a sentence without expressing exactly who is doing the hoping and how!
In other words, instead of denoting "done in a hopeful manner," today the word hopefully expresses the thought "I hope" in an unspecified and nebulous way.
Your sentence, "I assumed that you fed your dog, hopefully because you realized it was hungry, rather than because you felt guilty for leaving it alone for so long,"
is ponderous, to be sure, but your insertion of the word hopefully is both gratuitous and superfluous. Here is my more compact, succinct version:
I assumed you fed your dog because it was hungry and not because you felt guilty for leaving it alone so long.
In case you are thinking my primary criterion for judging the formation of sentences
is brevity or concision, allow me to disabuse you of that notion. Long--even convoluted--sentences can be good, necessary, and even powerful. Sometimes, however, economy of expression is also a good thing.
My grandfather used to say, "The more you say, the less the better," which is a homey way of saying the longer the sentence, the more likely misunderstanding (or something worse!) will ensue.
While your sentence communicates what I think you want it to communicate, you can save precious breath--not to mention space on the printed page--by paring down the sentence.
Your sentence contains 27 words; mine, 22. Now you could have begun your sentence with the words "I hope," and that would be fine (I assume you do hope your friend fed his dog because it was hungry and not for a lesser justifiable reason), and the word count would remain the same.
I hope you fed your dog because it was hungry and not because you felt guilty for leaving it alone so long.
In conclusion, neither your sentence nor your friend's sentence is incorrect; they're just bloated. Sometimes the less you say, the more the better.