Can any physician write contact lenses prescription or can it only be written by an opthomologist?

Usually eye doc. Usually a contact lens or spectacle prescription is written by an ophthalmologist or optometrist. Most other doctors do not have the required equipment to measure the prescription, translate it into the right contact lens prescription, and pick the right base curve and diameter for the contact. Finally if there is a problem, you will need to bring it to an eye doctor to recheck.
No limits. A contact lens prescription can be written by anyone with prescriptive authority. Non-ophthalmologists, however, are not trained in determining such a prescription and would be limited to copying the numbers from a prescription written by an ophthalmologist.