Option selling call selling and put selling

Does option writer has to hold the trade till expiry?

Not necessary, you can square off (buy back) on same day itself or any other day prior to expiry