You need to assign a scope "thisQuestion" for the elements so their insertion is not repeated.
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
// Identify this question
var thisQuestion = $('#question{QID}');
// Assign column-specific classes
$('table.subquestion-list tr', thisQuestion).each(function(i) {
$('> *:gt(0)', this).each(function(i){
$(this).addClass('column-'+(i+1));
$(this).attr('data-column', i+1);
});
});
// Hide the text inputs in columns 1 and 4
$('.column-1 input[type="text"]', thisQuestion).hide();
$('.column-2 input[type="text"]', thisQuestion).hide();
$('.column-3 input[type="text"]', thisQuestion).hide();
$('.column-4 input[type="text"]', thisQuestion).hide();
$('.column-5 input[type="text"]', thisQuestion).hide();
$('.column-6 input[type="text"]', thisQuestion).hide();
// Insert the checkboxes into column 1
$('.answer-item.column-1', thisQuestion).append('<input class="checkbox inserted-checkbox" type="checkbox" />');
$('.answer-item.column-2', thisQuestion).append('<input class="checkbox inserted-checkbox" type="checkbox" />');
$('.answer-item.column-3', thisQuestion).append('<input class="checkbox inserted-checkbox" type="checkbox" />');
$('.answer-item.column-4', thisQuestion).append('<input class="checkbox inserted-checkbox" type="checkbox" />');
$('.answer-item.column-5', thisQuestion).append('<input class="checkbox inserted-checkbox" type="checkbox" />');
$('.answer-item.column-6', thisQuestion).append('<input class="checkbox inserted-checkbox" type="checkbox" />');
// Initial checkbox states (if the question has already been answered)
$('.inserted-checkbox', thisQuestion).each(function(i) {
if($.trim($(this).closest('td').find('input[type="text"]:eq(0)').val()) == 'Y') {
$(this).prop('checked', true);
}
});
// Listener on the checkboxes (insert "Y" into hidden text input when checked)
$('.inserted-checkbox', thisQuestion).change(function() {
if($(this).is(':checked')) {
$(this).closest('td').find('input[type="text"]').val('Y');
}
else {
$(this).closest('td').find('input[type="text"]').val('');
}
});
});
</script>