The reason a prescription is required to buy heartworm medication is that a dog must be tested yearly to make sure they do not have heartworms. If they do and a heartworm pill is given, it can kill your dog. The dead worms can clog the arteries and stop the heart.
Also, the FDA has an entire warning about counterfeit heartworm products on the market. Buying them from someplace that doesn't require a prescription increases the risk that you will get a counterfeit product. You may be lulled into thinking that your dog is protected from this deadly disease when he is not.
http://www.fda.gov/fdac/features/2006/606_pets.html
Please, please do not pinch pennies with this particular medication and risk the health of your dog. Ask your vet if he will match the online price of a reputable pharmacy like KV Vet, Drs. Foster & Smith, etc. Many will to keep their patients safe.