Besides the reasons to provoke a lawsuit just to gain public attention which were already covered by the other answers, a "defendant" might sometimes bring up a potential infraction of themselves to the attention of a court in order to achieve a declaratory judgment.
Why would someone do that?
Often to get a legal uncertainty out of the world which might otherwise affect them at a later time where it will be far more inconvenient for them. For example, someone might plan to create a movie based on an intellectual property they might or might not have the rights to use. Perhaps what they want to do is covered by fair use... or not, a fair use defense is often kinda shaky. Perhaps it's already in the public domain, but the whole creation history of the work is kinda lost in the mists of time. Perhaps they might actually own the legal rights through some vague contract clause from 50 years ago between the creator and another company which then went through a wild history of mergers, splits, reincorporations, liquidations and acquisitions so nobody understands anymore who owns what IP rights... the whole legal situation is unclear. Their lawyers say that if the suspected copyright owner of the work sues them, then they might win or lose. It's a 50/50 matter which depends on a lot of unknowns and the mood of the judge.
When they proceed with the project, then they might waste millions of dollars and years of work on the project just to then get sued, lose and end up with a net loss. So what do they do to avoid that uncertainty?
They go to a court and request a declaratory judgment in the case. That way they can find out whether or not they have the right to do what they want to do before they start to invest time and money.