Prices for scholarly books are not set by the author but by the publisher. The author will often send you a PDF for free if you email and ask nicely.
That's the problem, though. One of my books costs more than $100 USD and that's even on the cheaper side, and as you rightly point out, I had zero choice or saying in the pricing. Some more established authors can influence it, either by publisher choice or by talking with the acquisition editor but that's rare.
The academic book publishing industry is very predatory, which is why so many authors nowadays support open textbook initiatives.
What I can say with certainty is that in many poorer countries scientific research would be impossible without piracy. Universities just don't have the budgets and libraries are often abysmal (unless you work in the capital and it has a prestige state library).
Sorry, I should have said "publish it" instead of "write it".