golang未在服务器应用程序中写入文件

I'm writing a simple tcp server in golang that writes to "output.txt". All the "server part" works fine, but it does not write to file.(but it does create "output.txt")

func handleRequest(conn net.Conn) {
 // Make a buffer to hold incoming data.
  buf := make([]byte, 1024)
  // Read the incoming connection into the buffer.
  size, err := conn.Read(buf)
  if err != nil {
    fmt.Println("Error reading:", err.Error())
  }
  s := string(buf[:size])
  fmt.Println(s)
  perm := os.FileMode(0644)
  err = ioutil.WriteFile("output.txt", buf, perm)
  check(err)
  // Close the connection when you're done with it.
  conn.Close()
}

Why does it not write to file and how to fix this?