Right.
There's much more to it than that.
The following is all rough math with no actual manufacturing costs of each company:
If you take my example numbers, it would cost $3 a cart. Let's say they do a production run of 100,000 carts for Switch. That's $300,000 in manufacturing right there.
To print the same quantity for PS4/XB1 it's about $75,000. ($0.75 a disc)
That's a $225,000 difference right there.
Keep in mind, console makers get a 30% cut and retailers usually get %20. So for the $29.99 retail price, the publisher gets $14.99 (50%).
If they only anticipate 100,000 copies sold for each platform, you're looking at revenue's of 1.5m for PS4 and XB1 copies minus the $75k each it took to print those discs (so a profit of 19.99% so let's round up to 20%).
If the switch version also sells all of the 100,000 copies at the same price of $29.99 minus the manufacturing of carts ($300k) you're looking at a profit of 1.5m - 300k = 1.2m. The profit margin of that is 4%.
Notice how the profit margin for retail PS4 and XB1 games is 20% vs the 4% of the Switch retail units? That isn't a big enough return on investment.
So in order to make up for that cost, they either need to sell many more switch copies or charge more for their game. They likely have a target sales number and market research that suggests it won't sell enough at retail to warrant the extra costs, therefore, they charge more.
So what happens when they charge $39.99? They get their 50% cut of each which is now $19.99. If they sell all 100k they manufactured at that price the profit margin becomes (4m revenue - 300k manufacturing = 3.6m) $3.7m/300k = 12.33% profit margin.
So basically, it's not just as simple as saying "carts don't cost $10 more to make so why is the game $10 more?" there's more to it than that.
Add in the risk of unsold copies and they need to add a little cushion. The publisher would probably need to sell it for $45 to get a profit margin on par with the disc based games.