updated file write code in QueryHandler