LPS-37491 Fix error (was writing empty files)