Cook onion slices in butter, then sprinkle with salt. Reduce heat to a gentle sizzle. During the last 5 minutes of cooking, add brown sugar and red wine vinegar.
Preheat oven to 400F.Roll out pie dough onto a parchment paper-lined baking sheet. Arrange caramelized onions on pie crust, leaving 2-3 inch of pie crust around the onions (reserve about a tbsp of caramelized onions).
Fold up edges of pie crust around the tomatoes. Brush the crust with beaten egg if using. Bake for 25-35 min, until crust is golden brown. After removing from the oven, scatter reserved caramelized onions and fresh basil on top.