From Adam Clarke's commentary,
*Most commentators are of opinion that Ezra was the author of the last
chapter of Deuteronomy; some think it was Joshua, and others the
seventy elders, immediately after the death of Moses; adding, that the
book of Deuteronomy originally ended with the prophetic blessing upon
the twelve tribes: 'Happy art thou, O Israel! who is like unto thee, O
people saved by the Lord,' etc.; and that what now makes the last
chapter of Deuteronomy was formerly the first of Joshua, but was
removed from thence and joined to the former by way of supplement.
This opinion will not appear unnatural if it be considered that
sections and other divisions, as well as points and pauses, were
invented long since these books were written; for in those early ages
several books were connected together, and followed each other on the
same roll. The beginning of one book might therefore be easily
transferred to the end of another, and in process of time be
considered as its real conclusion, as in the case of Deuteronomy,
especially as this supplemental chapter contains an account of the
last transactions and death of the great author of the Pentateuch." -
Alexander's Heb. and Eng. Pentateuch.(taken from here)
The best answer is from Deut. 31:24,
And it came to pass, when Moses had made an end of writing the words
of this law in a book, until they were finished
They were then placed in the Ark of the Covenant(vs 26).
Joshua was anointed to be Moses's successor, and it appears from the writing that it was talking about Moses in the 3rd person past, not 1st person present, therefore Joshua is seen to have written the last part of Deuteronomy, followed by the Book of Joshua,
And Joshua the son of Nun was full of the spirit of wisdom; for Moses
had laid his hands upon him: and the children of Israel hearkened unto
him, and did as the LORD commanded Moses
Since the fact that Moses's death was recorded, it is unlikely that he recorded his own death; yet modern interpretive scholarship must be rejected in that Moses, who wrote the Book(s) of the Law, and they were placed in the Ark of the Covenant, the most sacred place of keeping, since it was the manifest Presence of God amongst the Children of Israel, and accessable only by the high priest. It is therefore fitting, that the last chapter is eulogizing Moses(vs 10-12), before it is recorded officially that,(Josh. 1:1-2)
Now after the death of Moses the servant of the LORD it came to pass,
that the LORD spake unto Joshua the son of Nun, Moses' minister,
saying,
2Moses my servant is dead; now therefore arise, go over this Jordan,
thou, and all this people, unto the land which I do give to them, even
to the children of Israel.
The best answer is that it must be attributed to Joshua.