It's not illegal, but it can be highly questionable and doctors might face investigation and sanction for anything other than the most non-controversial script.
It also rather depends on where you are - if very remote, then it might be the best pragmatic solution.
If it's a private prescription, then it'll take a while and a pattern of behaviour before anyone even noticed what was happening.
Though pharmacists might question anything not on a good letterhead, and outside major cities it's not that common to handle private prescriptions at all