Second variations for domain optimization problems