Firstly, cognitive dissonance is not really being used well here and I don't like it being so trivialized. What OP feels is more guilt and confusion that his friend is worse paid than him and yet has to work harder. Cognitive dissonance is holding two conflicting beliefs at the same time in a way that creates a mental toll. What happens in abusive relationships or example when a person is told "i love you" while being hurt. Or when your gut feeling tells you something wrong is happening, but you're told everything is right. Cognitive dissonance feels almost like physical pain.
And about your comment:
SW aren't well paid because of how much money they generate or how hard they are to replace.
1- I'm not sure why you say this but SW are not that difficult to replace. There's plenty of SW around for everyone.
2- What actually determines the fact that SW are so well paid is just luck and time. What do I mean by this?
2.1 The profit margins in software services are the biggest. An easy example is Amazon. Initially a simple bookstore. Then a e-commerce shop. This is what Amazon is. And yet their margins for this is about 1% and for their cloud services is about 40%. Amazon CAN afford to pay SW well not because it generates more money, but because it has huge profit margins. And why is that?
2.2 Because it just so happens tech is VERY NEW and has changed everything far too fast for the market to adapt. Consumer physical products have been manufactured and sold for decades. Agriculture is a much more essential service than SW and it's some of the worst paid industry. Their profit margins are close to zero. All the money that could be extract has been, capitalism has done a good job of making it cheap for consumers. But tech? The world of mega corporations, monopolies and duopolies, there is often no such thing.
It's not about value to the world SW provide, money SW generate or hard to replace. If you really want to talk about value to the world there are many other careers that do. SW isn't one of them. SW are just well paid, due to luck, timing of being born right now, and the fact market is very new and hasn't adapted yet, that's it. Enjoy.