How can I make sure that leaving a job goes smoothly in terms of handing back the work permit?
Firstly, this is by and large the employer's responsibilty and not the teacher's.
You need to liaise with your school's admin person and tell them that you are leaving (hopefully you gave them 30 days notice) and discuss this issue.
Ask the employer to inform you as soon as your work permit has been cancelled and returned to the labor department. You must ensure that this procedure has been carried out or else getting your new work permit for the next job could be a problem.
Years ago, it was the responsibilty of the employer to give the teacher a chit to show that the permit had been cancelled but that's no longer the case. Therefore the current system is open to all sorts of administrative procrastination if your school is that way inclined.