The auditor general has issued a strongly critical report on Historic Environment Scotland following a period of "significant instability".