Preheat oven to 425 degrees. In a 9-by-13-inch baking dish, toss pears and onion with butter and vinegar. Season with salt and pepper. Arrange pears and onion in a single layer (they should fit snugly in dish) and top with rosemary. Cover dish tightly with foil and bake until pears begin to soften, 20 minutes. Uncover and bake until pears are golden brown on bottom and tender when pierced with a knife, 15 to 20 minutes more. Sprinkle with fresh rosemary leaves if desired and serve warm or at room temperature.