Let's take out for a moment that you are an honest person.
The fact is you wrote a BAD check. Certegy is a valid company, they are actually the ones who "guarantee" the checks for various merchants. That means that if the check is dishonored Walgreens still gets' their money. That is why they Walgreens didn't want you to pay them, because you don't owe them.
Now you still owe the money but it is to Certegy. However, because it was returned you may also be subject to additional fees. Depending on the State and exact situation you may be subject to a fee they could around $10 to 3-Times the amount of the check in addition to the original amount. The fact that you caught it before they did means nothing. The second the check was dishonored by the bank you are subject to these fees.
Certegy will contact you, most likely by mail based on the information on the check. They will tell you that you had a dishonored check and the amount you need to pay including the original amount and any fees.
Keep in mind that writing a bad check is a very serious matter and it does not matter if it was an honest mistake or not. If you do not pay what you owe they can(and often will) turn you over to your local District Attornies Check Restitution Program where you have a choice of paying or being charged with a crime.