The need for a Christian Scriptural canon arose in the early 2nd century, largely as a result of a heresy promulgated by Marcion of Sinope.
The origin of the New Testament canon can be traced to Marcion of Sinope, who lived between 110 and 160. Marcion believed that the significance of Christ came not in being the Incarnate Son of God, but rather in revealing a hitherto unknown benevolent God (or "god") who existed in opposition to the apparently malevolent Hebrew God. Justin Martyr, a contemporary of Marcion, mentions him in his First Apology:
And there is Marcion, a man of Pontus, who is even at this day alive,
and teaching his disciples to believe in some other god greater than
the Creator. And he, by the aid of the devils, has caused many of
every nation to speak blasphemies, and to deny that God is the maker
of this universe, and to assert that some other being, greater than
He, has done greater works.1
Marcion seems to have been the first to have proposed a rigid New Testament which included some writings and excluded others. As described by Tertullian2, Marcion accepted the writings of Luke (the Gospel and Acts) and ten of Paul's Epistles to the exclusion of all others and interpreted what remained to support his theology. (Tertullian seemed to have delighted in refuting Marcion from the same constrained set of texts).
Marcion was in large part the impetus for early Church Fathers to determine a "rule" of Scripture (Greek kanon) to ensure that the proper Apostolic writings (or writings attributed to the Apostles, directly or indirectly) were included in what was to be read in the Churches.
The history of the development of the canon subsequent to Marcion has been documented elsewhere (including on this site) - a history which includes the Muratorian Fragment and Athanasius' Festal Letter, as well as the formalization and finalization of the Biblical canon by the Church.
1 Chapter XXVI
2 Against Marcion, Book IV