This is why history isn't working for you. You forgot to bufio.NewWriter().Flush()

Given that this is supposed to be an example, I would suggest omitting bufio.* everywhere.