Greenock Morton beat fellow First Division promotion hopefuls Dunfermline 4-2 in a thriller at Cappelow Park.