Add helper for staged file writes

This creates a helper for staged file writes (where we write to a temporary file and then rename), uses it in the place where we had that logic, and then uses it (along with logging and error handling improvements) to improve the error behavior of the evaluator's component cache.