No difference between the two. CuI is an ionic, crystalline compound. It doesn't form discrete molecules of CuI, or of Cu2I2 for that matter. CuI is used because it is the simplest way to represent the ratio of copper and iodide ions in the compound. As long as the ratio of ions is correct, it doesn't matter what formula you use for an ionic compound (but the simplest one with whole number coefficients is always the most common).
For mercury(I) compounds, the formula is given as Hg2X2. This is done because mercury(I) ions form dimers in the crystal structure and (I think) aqueous solution: the two mercury atoms are always attached to each other, so it is treated as a polyatomic ion, like carbonate or sulfate.