No idea why it happened in one flask and not in another (were they using exactly the same reagents, in exactly the same amounts?), but why the iodine was produced is rather obvious - try to balance the redox equation describing the CuI precipitation from the Cu2+ solution.