Which one is correct:
To perform a task is necessary to do some things.
To perform a task it is necessary to do some things.
You need it:
The reason is that, in your sentence without it, the subject to do some things would come after the finite verb is: because it is generally not possible to have no subject before the verb, you need a dummy subject it to come before the verb, at least in non-inverted word order.
I think most people would add the comma here, though I'd not consider it absolutely necessary.
You even need it when used in a relative clause, according to style books:
The reason is that you couldn't replace it with the subject of the subordinate clause. Which refers to the Hanseatic League (the antecedent), and we should then be able to replace which with its antecedent:
But this sounds slightly off or different. It is not the Hanseatic League that is necessary in order to have x on our side: it is having the H. L. on our side as a whole that is necessary for some unmentioned purpose. (If this were possible, it would be a case of raising, as with it seems she has left us => she seems to have left us, where there is no difference in meaning.) We'd still need a dummy subject here:
Note that it would sound more natural to say we need the H. L. on our side.
Both are correct but they have different meanings. In addition, I would not use the first example.
Suppose that you have to click a button when you want to print out a document (in a computer program). Then I could say:
Note the difference in the order.
I prefer to use a comma in 1, but some people omit it.
I would not use 3 because it is hard to understand for me. This is because when I see “To click a button” at the beginning of the sentence, I expect a sentence like the first one and therefore expect to see a subject later, but actually “To click a button” is the subject. However, I would not say 3 is incorrect.
You should use the second one, but it's a bit unclear (in written form). Insert a comma:
Your second option is correct:
The reason for this is that the verb is needs a subject. Verbs in English always have to have an explicit subject, with a handful of exceptions (the imperative being the most common). Therefore, whenever we have a statement with no logical subject, we have to add the word it (or sometimes there) in order to act as a placeholder subject. For example:
The words it doesn't refer to anything in particular here, but it's required by the grammar of English to supply a subject.
In your sentence, you might be tempted to analyze the infinitive to perform a task as the subject. This is incorrect, however. The infinitive here is actually an adjunct, with an understood prepositional in order preceding it. You can demonstrate this by moving the infinitive to the end of the sentence:
Here's it's clear that to perform a task is an adjunct, and that the verb is requires the dummy subject it. The same thing applies, though somewhat less obviously, when the infinitive is moved to the beginning of the sentence.