writing output to handle