Why do people rarely execute options and instead sell the contract?
If there is any time premium remaining, selling the option rather than exercising it throws that time premium away. Assume that we're talking about a long call (it's the same for long puts except for the positions and direction). If you don't want to own the underlying then you will have more frictional costs by exercising the call and then having to sell the stock.
If the call is ITM and/or near expiration, it may trade for below parity (negative intrinsic value) and exercising it will avoid the haircut. For example, XYZ is $100 and you own a $95 call that is trading for $4.75 x $5.25. The intrinsic value of the call is $5. If you sell at the market, you lose 25 cents. You could place an order to sell at $4.95 and you might get lucky. or not. But what if XYZ drops $1 while you are waiting for a fill? Now tyour intrinsic value is only $4 and you have lost a $1 and you still have that illiquid option on your hands.
At $100, exercise the call to buy 100 shares at $95 and simultaneously sell the stock at $100. The gross is $500 (less commissions). I trade at IBKR so assignment and exercise are free so it's one commission either way I do it.
As for what happens if the contract expires in the money and you havent sold the contract contrary to another reply, it is automatically exercised.
“Exercise by Exception" is the Options Clearing Corporation provision for the automatic exercise of in-the-money options at expiration. They will automatically exercise any expiring EQUITY call or put that is $0.01 or more in-the-money. However, a specific brokerage firm’s threshold for such automatic exercise may or may not be the same as OCC’s. If you are long the option, you can designate to your broker that te OCC does not exercise your in-the-money option by any amount. The person who is short the option must close it prior to expiration to avoid this. INDEX options are settled in cash.