The worms are probably tubifex and harmless. 30 years ago most pet shops sold live tubifex and most peiple fed them to their fish. They would come in with live food or plants from a waterway. They will be thrivng on left over food and waste as will the planaria. The dose of formalin to kill planaria is 12mls of 35% per 100litres and will kill plants and fish. The easiest way is to cut right back on feeding and vacuum the media regularly.