Properly close and remove file in daemon test Upstream-commit: 45865bc4f5e21b2208859c62985a9c4f85660b42 Component: engine