The way teachers manage classroom discussion with pupils plays a key role in the teaching of writing, a new study shows.