The wandering backwards and forwards is to keep the tyres warm. Those tyres are designed to be hot. So they are heated before they are put on the car and during racing all that force keeps them hot. Behind the safety car those tyres start to cool down so the drivers weave to keep them warm.