Preheat the oven to 400°F. Lightly grease an 8-inch cast-iron or other oven-safe skillet.
Remove the husks and silk from the corn, then carefully cut the kernels from both cobs.
Combine the corn, mayonnaise, mozzarella, sugar, green onions, salt, and black pepper in a mixing bowl. Stir until evenly coated.
Transfer the mixture to the prepared skillet and spread it into an even layer.
Bake for 10 minutes, or until the cheese has melted and the mixture is visibly bubbling.
Switch the oven to broil. Broil for approximately 2 minutes, watching continuously, until the cheese is browned in spots.
Carefully remove the hot skillet and serve immediately.