Fixed error that was writing an extra empty file