Derailed Perth to Inverness train was wrongly diverted in incident that shut the line for almost a week