The Government is set to bail out Scotland's biggest building society after it racked up millions in losses.