move closing of filtered file before binarizing. Otherwise file not flushed, causes error in binarizing