New Zealand has preserved a 120-year unbeaten record against Scotland after winning a gripping contest 25-17 at Murrayfield.