I used an ATM to withdraw a certain sum of money from my bank account. The transaction processed as normal, but the cash dispensed was $20 greater than I had asked for. The machine gave me a receipt that I had withdrawn the amount I asked for (i.e. without the extra $20) and my bank told me that they only have a record of the amount that I had requested being withdrawn. What are my legal obligations here?
You are obliged to report the error in writing to you Bank.
Scenario 1: Just for your transaction, the ATM counting machine dispensed additional $20. Generally the Bank recons per ATM, the actual disbursements and the balance cash. In this specific case, they should find out the discrepancy and deduct the extra $20 from your account.
Scenario 2: The previous transaction did not spit out the exact cash, and gave $20 less to the person before you. He did not notice it and report. You got the additional $20 which was stuck. In this case it may be difficult for Bank to identify and rectify; they may take no action.
More often the cash loading as the upkeep of ATM is outsourced to 3rd party. There are known causes [0.01%] that at times result in less or excess cash being disbursed. The outsourced agency eats up this cost as normal business expense. So unless there is a huge discrepancy; i.e. loading trays with incorrect denominations, or major glitch; they don't bother as the cost to recon a $20 is less than the actual effort ... so they just ignore it.
Your MORAL obligation is to contact the bank and inform them of the mistake. If you accidentally paid someone $20 too much, you would certainly expect them to tell you that you made a mistake and give you back the extra money.
Your LEGAL obligation depends on the laws of your country and maybe state/province. But I suspect that in most of the world you'd be required to give back the extra money. I just did some searching to find the text of the law and couldn't find any actual legal text, so there may be technicalities, etc.
I'd notify the bank of the mistake in writing, because if you just walked in and handed back the money and it was not properly recorded, and then the bank found the problem, they could demand you pay it back again.
You have $20 that doesn't belong to you. Although a lot of people believe in 'finders keepers', the law in most countries is quite clear, intending to permanently deprive another of property belonging to them and doing so, is Theft.
You should make reasonable attempts to contact the owner of the property (the operator of the ATM - not your bank unless they are the operator) and return it to them. Their details should be provided on the ATM receipt or on the machine itself. If not, the building owner where the ATM is located should know. They may say 'don't worry about it', or they might send you a bill, or may have already called the police. Be aware however, the actual $20 note is the property, not the amount, so don't spend it if you can. There could be uncertainty about which of the $20 notes you received, but it would seem reasonable to pick the last one (if you still can, if not one of the $20 you can still identify). The implication is that even if you returned them the money, they could still claim that you did not return their property (!).
If you make several good faith attempts to return the property to the owner and are unable to do so, you may under certain circumstances be able to keep the property. Your state may have statutory method for dealing with abandoned property.