I've heard of folks doing charitable donations of their earnings but not giving away books. I've often heard of it in the context of not being the best career move. It's very nice of you, but it may not increase sales and future publishers will look at sales numbers before deciding whether to take you on.
That said. You'd have to decide how the books will be delivered and to where. How can you be sure they get in the hands you want them in? All of this would be in your contract. You might be better off taking the advance and then buying author copies at your discount to donate. (That might lead to a bigger donation.) Do note that you are the one making the donation (possibly in both scenarios), so the books will still count as income. In other words, there are tax implications too.