Well, Herodotus for a start...
That greatly depends on what you consider "writing for posterity". If you mean attempting to create a factual, unbiased account of happenings which was published and distributed, then yes, Herodotus has a claim to be the first historian. However, if you define it as "writing something for the future and public to see and understand something you wish to communicate to the future", then you need to look much further back, to ancient monumental inscriptions, the oldest of which come from Mesopotamia, such as this monumental inscription from ancient Sumer written by Lugalanamundu, king of Adab, dating to around 1900-1600 BC. These accounts are largely propagandistic, though through them we can understand some actions of certain people and the dates at which they happened (the building of a temple, the fighting of a battle, the victor of said battle, a war, etc).
Or you may also consider that ancients would write down lists of the kings who ruled, as found in the Sumerian King Lists.
Personally, I count these as writing for posterity, as they were written so that future generations would note the accomplishments of certain people in their history. If this is not what you were looking for, however, I can understand.
In that case, scholars generally agree that Herodotus of Halicarnassus (484-425 BC) wrote The Histories and it was the first critical historical work.