In most states, the law explicitly requires the pharmacist to fill a prescription with a generic (if available) unless the doctor specifically writes "dispense as written". Not allows - requires.
The purpose of these laws is to protect patients - in the overwhelming majority of cases, the generic and brand name drugs are equivalent for patients, so patients save money by purchasing the generic medication even if the physician prescribed the drug using its more well-known name (the brand name).