Producing goods often creates negative externalities, such as bad working conditions. Usually, people do not want to harm a third party when they can decide individually but competition might promote unethical behavior. In a social dilemma game with an affected but inactive third party we let players form a costly institution that allows informal punishment to reduce externalities and competitive disadvantages. An exogenous implemented punishment institution reduces the harm imposed on a third party but social welfare decreases compared to the standard game due to losses by severe punishment. When players can choose to join groups that implemented the punishment institution endogenously, such groups act in favor of the third party and do not punish each other. In this case social welfare increases significantly. However, only a third of all participants choose the punishment institution, so that social welfare in total is not affected.