The order of a conjugacy class is bounded by the index of the center

Your proof is correct, but you can simplify the end by saying that $$[G:C_G(g_i)] \leq [C_G(g_i):Z(G)]\cdot[G:C_G(g_i)] =n$$ Actually a contradiction is not needed.