Preheat your oven to 400°F.
In a large mixing bowl, combine the drained sweet corn, shredded mozzarella cheese, mayonnaise, sugar, garlic powder, salt, black pepper, and chopped green onions. Mix well until all ingredients are evenly combined.
Transfer the corn mixture into a baking dish and spread it out evenly.
Dot the top with small pieces of butter.
Bake in the preheated oven for 20-25 minutes, or until the cheese is melted and bubbly, and the top is lightly golden.
Remove from the oven and let it cool for a few minutes.
If desired, sprinkle with red pepper flakes for added heat before serving.